<template>
	<div>

		<el-tabs v-model="state.activeName" class="demo-tabs">
			<el-tab-pane label="提现时间配置" name="first">
				<el-form
					ref="formRef"
					:model="state.form"
					label-width="120px">
					<el-form-item
						label="可提现日期"
						prop="withdrawDate"
						:rules="[
        {
          required: true,
          message: '可提现日期不能为空',
          trigger: 'blur',
        },

      ]"
					>
						<el-select
							v-model="state.form.withdrawDate"
							multiple
							placeholder="请选择日期"
							style="width: 240px"
						>
							<el-option
								v-for="item in 31"
								:key="item"
								:label="item"
								:value="item"
							/>
						</el-select>
					</el-form-item>
					<el-form-item label="每天提现次数"
												prop="withdrawNum"
												:rules="[
        {
          required: true,
          message: '每天提现次数不能为空',
          trigger: 'blur',
        },

      ]"
					>
						<el-input-number v-model.number="state.form.withdrawNum" :min="1" :max="10" />
					</el-form-item>
					<el-form-item label="可提现星期"
												prop="withdrawWeek"
												:rules="[{
          required: true,
          message: '可提现星期不能为空',
          trigger: 'blur',
        },
      ]">
						<el-select
							v-model="state.form.withdrawWeek"
							multiple
							placeholder="请选择提现星期"
							style="width: 240px"
							:multiple-limit="2"
						>
							<el-option
								v-for="item in 7"
								:key="item"
								:label="item"
								:value="item"
							/>
						</el-select>
					</el-form-item>
					<el-form-item label="可提现小时" prop="withdrawHour"
												:rules="[
        {
          required: true,
          message: '可提现小时不能为空',
          trigger: 'blur',
        },

      ]">
						<el-select
							v-model="state.form.withdrawHour"
							multiple
							placeholder="请选择提现小时"
							style="width: 240px"
							:multiple-limit="2"
						>
							<el-option
								v-for="item in 24"
								:key="item"
								:label="item + '点'"
								:value="item"
							/>
						</el-select>
					</el-form-item>

					<el-form-item>
						<el-button type="primary" @click="dateForm(formRef)">确定</el-button>
					</el-form-item>
				</el-form>
			</el-tab-pane>
			<el-tab-pane disabled label="账号奖金" name="second">

      </el-tab-pane>

			<el-tab-pane label="文件上传" name="third">
				<el-radio-group v-model="state.fileConfig">
					<el-radio value="1" size="large">本地</el-radio>
					<el-radio value="2" size="large">七牛云</el-radio>
					<el-button type="primary" @click="btn(state.fileConfig)">确定</el-button>
				</el-radio-group>
			</el-tab-pane>

		</el-tabs>
	</div>
</template>
<script setup lang="ts">
import type { FormInstance } from 'element-plus'
const formRef = ref<FormInstance>()
const state = reactive({
	fileConfig:null,
	activeName: 'first',
	form: {
		withdrawDate: [],
		withdrawNum: 0,
		withdrawWeek: [],
		withdrawHour: []
	}
})

function init() {
  http.get("/api/admin/config/get").then(res =>{
    state.form.withdrawNum  = res.data.withdrawNum
    state.form.withdrawDate  = res.data.withdrawDate
    state.form.withdrawWeek  = res.data.withdrawWeek
    state.form.withdrawHour  = res.data.withdrawHour
  })


	postRequest("/api/config/getConfig",{type:"uploadType"}).then(res =>{
	 		state.fileConfig = res.data[0].value
	})

}
onMounted(() =>{
  init()
})


const btn = (data:string) => {

}

/**
 * 日期配置
 * @param formEl
 */
const dateForm = (formEl: FormInstance | undefined) => {
	if (!formEl) return
	formEl.validate((valid) => {
		if (valid) {
			const request = {
				withdrawDate: state.form.withdrawDate.join(","),
				withdrawNum: state.form.withdrawNum,
				withdrawWeek: state.form.withdrawWeek.join("-"),
				withdrawHour: state.form.withdrawHour.join("-"),
			}
      http.post("/api/admin/config/update",request).then(() =>{
         init()
          toast.success("修改成功")

      })


		} else {
			console.log('error submit!')
			return false
		}
	})
}


</script>
<style scoped>

</style>
